﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using COMMON;
using WLWeb.PulbicClass;

namespace WLWeb.Common
{
    public partial class JianZhan : System.Web.UI.Page
    {
        WLong.BLL.CustomerMessage bcustomer = new WLong.BLL.CustomerMessage();
        WLong.Model.CustomerMessage mcustomer = new WLong.Model.CustomerMessage();
        BLL.wlBLL.BLL_WebExample webexample = new BLL.wlBLL.BLL_WebExample();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            #region 条件验证
            if (txtVerifyCode.Value.Trim() == "")
            {
                Webpublic.ShowMessage(this, "验证码不正确!");
                return;
            }
            if (Session["CheckCode"] != null)
            {
                if (txtVerifyCode.Value.Trim() != Session["CheckCode"].ToString())
                {
                    Webpublic.ShowMessage(this, "验证码不正确!");
                    return;
                }
            }

            if (txtMobile.Value == "")
            {
                Webpublic.ShowMessage(this, "手机不能为空!");
                return;
            }
            if (COMMON.ControlCommon.IsExsitMebile(txtMobile.Value.Trim())==false)
            {
                Webpublic.ShowMessage(this, "您输入的手机号码不正确!");
                return;
            }
            if (txtTruename.Value.Trim() == "")
            {
                Webpublic.ShowMessage(this, "用户姓名不能为空!");
                return;
            }
            if (txtTelephone.Value.Trim()!="" && COMMON.ControlCommon.IsExsitTelephone(txtTelephone.Value.Trim()) == false)
            {
                Webpublic.ShowMessage(this, "您输入的固定电话号码不正确格式:XXX-XXXXXXXX!");
                return;
            }
            if (txtEmail.Value.Trim()!="" && COMMON.ControlCommon.IsExsitEmail(txtEmail.Value) == false)
            {
                Webpublic.ShowMessage(this, "您输入的邮箱地址格式不正确!");
                return;
            }
            if (txtAddress.Value.Trim() == "")
            {
                Webpublic.ShowMessage(this, "详细地址不能为空!");
                return;
            }
            if (txtContent.Value.Trim() == "")
            {
                Webpublic.ShowMessage(this, "留言内容不能为空!");
                return;
            }
            #endregion
            mcustomer.CustomerName = txtTruename.Value.Trim();
            mcustomer.CustomerMobile = txtMobile.Value.Trim();
            mcustomer.CustomerMessageID = Guid.NewGuid();
            mcustomer.CustomerContent = txtContent.Value.Trim();
            mcustomer.CustomerEmail = txtEmail.Value.Trim();
            mcustomer.CustomerTelephone = txtTelephone.Value.Trim();
            mcustomer.Disabled = 0;
            mcustomer.REC_CreateBy = Webpublic.GetIPAddr();
            mcustomer.REC_CreateTime = DateTime.Now;

            if (webexample.AddCustomerMessage(mcustomer))
            {
                Webpublic.ShowMessage(this, "留言成功!");
                btnSubmit.Enabled = false;
                return;
            }
            else
            {
                Webpublic.ShowMessage(this, "留言失败!");
                return;
            }
            //if (bcustomer.Add(mcustomer))
            //{
            //    Webpublic.ShowMessage(this, "留言成功!");
            //    btnSubmit.Enabled = false;
            //    return;
            //}
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtAddress.Value = "";
            txtContent.Value = "";
            txtEmail.Value = "";
            txtMobile.Value = "";
            //txtQQ.Value = "";
            txtTelephone.Value = "";
            txtTruename.Value = "";
            txtVerifyCode.Value = "";

        }
    }
}